// 引入 mongoose 包
const mongoose = require('mongoose')

// 连接数据库
mongoose.connect('mongodb://localhost:27017/test',)

// 通过 Schema 定义接口
const Schema = mongoose.Schema 

// 设置数据类型
const StudentSchema = new Schema({
  name:{
    type: 'string',
    required: true
  },
  gender:{
    type: 'string',
    enum:['男','女'],
    default: '男',
    required: true
  },
  age:{
    type: 'number',
    required: true
  },
  hobbies:{
    type: 'Array'
  },
})

// 将此 Students 模型暴露出去
module.exports = mongoose.model('Students',StudentSchema );


